<?php /*a:3:{s:60:"D:\projects\original_admin\app\merchant\view\order\list.html";i:1754743201;s:61:"D:\projects\original_admin\app\merchant\view\common\base.html";i:1752764603;s:63:"D:\projects\original_admin\app\merchant\view\common\header.html";i:1754793874;}*/ ?>
<!DOCTYPE html>
<html lang="zh-CN">

<head>
	<meta charset="UTF-8" />
	<meta name="renderer" content="webkit" />
	<meta name="force-rendering" content="webkit" />
	<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>管理系统</title>
	<script src="/static/merchant/js/jquery-min.js"></script>
	<link rel="stylesheet" href="/static/merchant/layui/css/layui.css">
	<script type="text/javascript" src="/static/merchant/layui/layui.js"></script>
	<link rel="stylesheet/less" type="text/css" href="/static/merchant/css/index.less" />
	<script src="/static/merchant/js/less.js"></script>
    
</head>
<body>
	<main class="CenterMain">
		<header class="Header">
    <div class="logo img_box">
        <img src="/static/merchant/images/logow.png">

    </div>
    <div class="top">
        <ul class="nav-buttons">
            <li id="toggle-btn">

                <span class="desktop-text layui-icon layui-icon-spread-left">
                </span>
                <span class="mobile-text">菜单</span>
            </li>
        </ul>
        <dl class="menu-btn">
            <a class="img_box ">
                <img src="/static/merchant/images/head1.png">
                <i class="msg"></i>
            </a>
            <a class="img_box">
                <img src="/static/merchant/images/head2.png">
            </a>
        </dl>
        <span class="hr"></span>
        <ul class="layui-nav">

            <li class="layui-nav-item" lay-unselect>
                <a href="javascript:;">
                    <img src="/static/merchant/images/sign-user.png" class="layui-nav-img">
                    <span><?php echo htmlentities((string) $userInfo['shop_name']); ?></span>
                </a>
                <dl class="layui-nav-child">
                    <dd><a href="account_info.html">个人信息</a></dd>
                    <dd><a href="account_pwd.html">密码修改</a></dd>
                    <dd style="text-align: center;"><a href="">退出</a></dd>
                </dl>
            </li>
        </ul>
    </div>

</header>
<div class="Sidebar" id="sidebar">
    <ul class="menu">
        <li class="menu-item">
            <div lay-on="url" href="/" class="title">
                <div class="img img_box">
                    <img class="img1" src="/static/merchant/images/nav22.png">
                    <img class="img2" src="/static/merchant/images/nav21.png">
                </div>
                <span>商品管理</span>
                <!-- <i class="layui-icon layui-icon-right"></i> -->
            </div>
        </li>
        <li class="menu-item <?php if($routers == 'order/list' || $routers == 'order/shop_back' || $routers == 'order/review'): ?>  active <?php endif; ?>">
            <div class="title">
                <div class="img img_box">
                    <img class="img1" src="/static/merchant/images/nav32.png">
                    <img class="img2" src="/static/merchant/images/nav31.png">
                </div>
                <span>订单管理</span>
                <i class="layui-icon layui-icon-right"></i>
            </div>
            <dl    <?php if($routers == 'order/list' || $routers == 'order/shop_back' || $routers == 'order/review'): ?>  style="display: block;" <?php else: ?> style="display:none;" <?php endif; ?> >
                <dd>
                    <a href="/merchant/order.html"  <?php if($routers == 'order/list'): ?>  class="active" <?php endif; ?> >订单管理</a>
                </dd>
                <dd>
                    <a href="/merchant/shop_back.html" <?php if($routers == 'order/shop_back'): ?>  class="active" <?php endif; ?>>退货管理</a>
                </dd>
                <dd>
                    <a href="/merchant/review.html" <?php if($routers == 'order/review'): ?>  class="active" <?php endif; ?>>订单评价</a>
                </dd>

            </dl>

        </li>
        <li class="menu-item <?php if($routers == 'finance/finance_cash'): ?>  active <?php endif; ?>">
            <div class="title">
                <div class="img img_box">
                    <img class="img1" src="/static/merchant/images/nav42.png">
                    <img class="img2" src="/static/merchant/images/nav41.png">
                </div>
                <span>财务提现</span>
                <i class="layui-icon layui-icon-right"></i>
            </div>

            <dl style="display: none;">
                <dd>
                    <a  <?php if($routers == 'finance/finance_cash'): ?>  class="active" <?php endif; ?> href="/merchant/finance_cash.html">提现</a>
                </dd>
                <dd>
                    <a href="finance_logs.html">记录</a>
                </dd>
            </dl>

        </li>
        <!-- <li class="menu-item ">
            <div class="title">
                <div class="img img_box">
                    <img class="img1" src="images/nav52.png">
                    <img class="img2" src="images/nav51.png">
                </div>
                <span>消息中心</span>
                <i class="layui-icon layui-icon-right"></i>
            </div>

        </li> -->
        <li class="menu-item ">
            <div class="title">
                <div class="img img_box">
                    <img class="img1" src="/static/merchant/images/nav62.png">
                    <img class="img2" src="/static/merchant/images/nav61.png">
                </div>
                <span>店铺设置</span>
                <i class="layui-icon layui-icon-right"></i>
            </div>

            <dl style="display: none;">
                <dd>
                    <a href="store_info.html">店铺信息 </a>
                </dd>
                <dd>
                    <a href="store_notice.html">店铺公告</a>
                </dd>
                <dd>
                    <a href="store_model.html">运费模板</a>
                </dd>
            </dl>

        </li>
    </ul>
</div>
		 
<div class="Content" id="content">
    <div class="container">
        <!-- 搜索栏 -->
        <form class="layui-form search-form SearchCom " lay-filter="searchForm">
            <div class="OrderSearcItem">
                <!-- <div class="input-inline ">
                    <select name="category" lay-search>
                        <option value="">商品分类</option>
                        <option value="1">定制实物</option>
                        <option value="2">设计原创</option>
                    </select>
                </div> -->

                <ul id="statusTab">
                    <a class="item active" data-status="">全部</a>
                    <a class="item" data-status="0">待支付</a>
                    <a class="item" data-status="1">待发货</a>
                    <a class="item" data-status="2">待收货</a>
                    <a class="item" data-status="3">完成订单</a>
                    <a class="item" data-status="-1">取消订单</a>
                    <a class="item" data-status="4">退货</a>
                </ul>

                <div class="layui-form-item">
                    <div class="layui-input-wrap">
                        <div class="layui-input-prefix">
                            <i class="layui-icon layui-icon-search"></i>
                        </div>
                        <input type="text" name="keyword" placeholder="订单号/买家/商品名" class="layui-input" value="<?php echo htmlentities((string) (app('request')->param('keyword') ?: '')); ?>">
                    </div>
                    <button class="layui-btn layui-btn-blue" style="margin-right: 20px;" lay-submit lay-filter="search">查询</button>
                </div>
            </div>
        </form>

        <!-- 商品表格 -->
        <table class="layui-hide" id="productTable" lay-filter="productTable" lay-skin="line"></table>
    </div>
    <script type="text/html" id="deliverTpl">
        <form class="layui-form" lay-filter="deliverForm" style="padding: 20px;">
            <div class="layui-form-item" style="margin-bottom: 15px;">
                <label class="layui-form-label" style="white-space: nowrap;">物流单号</label>
                <div class="layui-input-block">
                    <input type="text" name="express_name" lay-verify="required" placeholder="请输入物流" 
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item" style="margin-bottom: 15px;">
                <label class="layui-form-label" style="white-space: nowrap;">物流单号</label>
                <div class="layui-input-block">
                    <input type="text" name="express_no" lay-verify="required" placeholder="请输入物流单号" 
                           autocomplete="off" class="layui-input">
                </div>
            </div>
      
        </form>
    </script>
    <!-- 状态模板 -->
    <script type="text/html" id="statusTpl">
        {{#  if(d.status === '待审核'){ }}
        <span class="layui-badge layui-bg-orange">{{ d.status }}</span>
        {{#  } else if(d.status === '已通过'){ }}
        <span class="layui-badge layui-bg-green">{{ d.status }}</span>
        {{#  } else if(d.status === '未通过'){ }}
        <span class="layui-badge layui-bg-red">{{ d.status }}</span>
        {{#  }}}
    </script>

    <!-- 操作按钮模板 -->
    <script type="text/html" id="operateTpl">
        <div class="foot">
            <a class="btn-edit" lay-event="view">查看</a>
            {{#  if(d.status_text === '待支付'){ }}
            <span>|</span>
            <a class="btn-delete" lay-event="cancel">取消</a>
            {{#  } else if(d.status_text === '待发货'){ }}
            <span>|</span>
            <a class="btn-edit" lay-event="deliver">发货</a>
            {{#  } else if(d.status_text === '待收货' || d.status_text === '已收货'){ }}
            <span>|</span>
            <a class="btn-delete" lay-event="refund">退款</a>
            {{#  } }}
        </div>
    </script>
</div>

	</main>
</body>
<script  src="/static/merchant/js/index.js"></script>
<script src="/static/merchant/js/base.js"></script>
 
<script>
    changeTitleName('订单管理')

    layui.use(['table', 'form', 'laydate'], function () {
        var table = layui.table;
        var form = layui.form;
        var laydate = layui.laydate;
        var $ = layui.$;

        // 初始化状态参数
        var currentStatus = getUrlParam('status') || '';
        var currentKeyword = getUrlParam('keyword') || '';
        
        // 设置初始选中状态
        $('#statusTab .item').removeClass('active');
        $('#statusTab .item[data-status="' + currentStatus + '"]').addClass('active');
        
        // 渲染日期选择器
        laydate.render({
            elem: '#publishTime',
            range: true
        });
        
        // 初始化表格
        var tableIns = table.render({
            elem: '#productTable',
            url: '/merchant/merchant-order-list',
            height: 'full-100',
            where: {
                status: currentStatus,
                keyword: currentKeyword
            },
            page: {
                limit: 17,
                limits: [10, 17, 20, 30],
                groups: 5,
                prev: '<',
                next: '>',
                layout: ['count', 'prev', 'page', 'next', 'limit', 'skip'],
                theme: '#1E9FFF'
            },
            cols: [
                [
                    {
                        field: 'name',
                        title: '商品信息',
                        width: 400,
                        templet: function(d) {
                            return `
                            <div class="goods-container">
                                ${d.cart_detail.map(item => `
                                    <div class="shopName">
                                        <div class="img img_100">
                                            <img src="${item.cart_info.thumb}" alt="${item.name}">
                                        </div>
                                        <div class="info">
                                            <p>${item.cart_info.productInfo.store_name}</p>
                                            <p>${item.cart_info.suk||''}</p>
                                            <p>×${item.cart_info.cart_num}</p>
                                        </div>
                                    </div>
                                `).join('')}
                            </div>`;
                        }
                    },
                    { field: 'order_id', title: '订单号', width: 250 },
                    { field: 'add_time', title: '下单时间' },
                    { field: 'nickname', title: '买家' },
                    { 
                        field: 'real_name', 
                        title: '收货信息',
                        width: 300,
                        templet: function(d) {
                            return d.real_name + ' ' + d.user_address + '<br>' + d.user_phone;
                        } 
                    },
                    { field: 'total_price', title: '总金额' },
                    { field: 'pay_price', title: '支付金额' },
                    { field: 'total_num', title: '数量' },
                    {
                        field: 'status', 
                        title: '状态', 
                        templet: function(d) {
                            var statusClass = '';
                            switch (d.status_text) {
                                case '未支付': statusClass = 'layui-badge layui-bg-orange'; break;
                                case '待发货': statusClass = 'layui-badge layui-bg-blue'; break;
                                case '待收货': statusClass = 'layui-badge layui-bg-prop'; break;
                                case '已收货': statusClass = 'layui-badge layui-bg-green'; break;
                                case '已取消': statusClass = 'layui-badge layui-bg-orange'; break;
                                case '申请退款': statusClass = 'layui-badge layui-bg-red'; break;
                            }
                            return '<span class="' + statusClass + '">' + d.status_text + '</span>';
                        }
                    },
                    {
                        title: '操作',
                        width: 160,
                        toolbar: '#operateTpl'
                    }
                ]
            ]
        });

        // 状态标签点击事件
        $('#statusTab .item').on('click', function(e) {
            e.preventDefault();
            var status = $(this).data('status');
            
            // 更新选中状态
            $('#statusTab .item').removeClass('active');
            $(this).addClass('active');
            
            // 更新URL参数
            updateUrlParam('status', status);
            
            // 重新加载表格
            tableIns.reload({
                where: {
                    status: status,
                    keyword: currentKeyword
                },
                page: { curr: 1 }
            });
        });

        // 搜索表单提交
        form.on('submit(search)', function(data) {
            currentKeyword = data.field.keyword;
            
            // 更新URL参数
            updateUrlParam('keyword', currentKeyword);
            
            // 重新加载表格
            tableIns.reload({
                where: {
                    status: currentStatus,
                    keyword: currentKeyword
                },
                page: { curr: 1 }
            });
            return false;
        });
        // 监听行工具事件
        table.on('tool(productTable)', function(obj) {
            var data = obj.data;
            switch (obj.event) {
                case 'view':
                    window.location.href = 'order_info.html?id=' + data.order_id;
                    break;
                case 'cancel':
                    layer.confirm('确定要取消该订单吗？', function(index) {
                        // 执行取消操作
                        $.post('/merchant/order/cancel', {order_id: data.order_id}, function(res) {
                            if(res.code === 0) {
                                layer.msg('取消成功');
                                tableIns.reload();
                            } else {
                                layer.msg(res.msg || '取消失败');
                            }
                        });
                        layer.close(index);
                    });
                    break;
                    case 'deliver':
                    // 发货弹窗
                    layer.open({
                        type: 1,
                        title: '订单发货',
                        content: $('#deliverTpl').html(),
                        area: ['450px', '300px'],  // 调整弹窗大小
                        btn: ['确认发货', '取消'],
                        success: function(layero, index) {
                            // 重新渲染表单
                            form.render();
                            
                            // 自动聚焦到输入框
                            layero.find('input[name="express_no"]').focus();
                        },
                        yes: function(index, layero) {
                            var express_no = layero.find('input[name="express_no"]').val().trim();
                            var express_name = layero.find('input[name="express_name"]').val().trim();
                            if(!express_no) {
                                layer.msg('请输入物流单号');
                                return false;
                            }
                            
                            // 显示加载中
                            var loading = layer.load(1);
                            
                            // 执行发货操作
                            $.post('/merchant/merchant-order-deliver', {
                                order_id: obj.data.order_id,
                                express_no: express_no,
                                express_name: express_name
                            }, function(res) {
                                layer.close(loading);
                                if(res.code === 200) {
                                    layer.msg('发货成功', {icon: 1});
                                    tableIns.reload();
                                    layer.close(index);
                                } else {
                                    layer.msg(res.msg || '发货失败', {icon: 2});
                                }
                            }).fail(function() {
                                layer.close(loading);
                                layer.msg('网络错误，请重试', {icon: 2});
                            });
                        }
                    });
                break;
                case 'refund':
                    // 退款弹窗
                    layer.open({
                        type: 1,
                        title: '订单退款',
                        content: `
                        <form class="layui-form" lay-filter="refundForm" style="padding: 20px;">
                            <div class="layui-form-item">
                                <label class="layui-form-label" style="width:100px">退款金额</label>
                                <div class="layui-input-block">
                                    <input type="number" name="refund_amount" lay-verify="required|number" 
                                        value="${data.pay_price}" placeholder="请输入退款金额" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label" style="width:100px">退款原因</label>
                                <div class="layui-input-block">
                                    <textarea name="refund_reason" lay-verify="required" placeholder="请输入退款原因" class="layui-textarea"></textarea>
                                </div>
                            </div>
                        </form>`,
                        area: ['500px', '300px'],
                        btn: ['确认退款', '取消'],
                        yes: function(index, layero) {
                            var form = layui.form;
                            form.on('submit(refundForm)', function(data){
                                // 执行退款操作
                                $.post('/merchant/merchant-order-refund', {
                                    order_id: obj.data.order_id,
                                    refund_amount: data.field.refund_amount,
                                    refund_reason: data.field.refund_reason
                                }, function(res) {
                                    if(res.code === 200) {
                                        layer.msg('退款成功', {icon: 1});
                                        tableIns.reload();
                                        layer.close(index);
                                    } else {
                                        layer.msg(res.msg || '退款失败');
                                    }
                                });
                                return false;
                            });
                            form.submit('refundForm');
                        }
                    });
                    break;
            }
        });

        // 获取URL参数
        function getUrlParam(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return decodeURI(r[2]); return null;
        }

        // 更新URL参数（不刷新页面）
        function updateUrlParam(key, value) {
            var url = window.location.href;
            var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
            var separator = url.indexOf('?') !== -1 ? "&" : "?";
            
            if (url.match(re)) {
                url = url.replace(re, '$1' + key + "=" + value + '$2');
            } else {
                url = url + separator + key + "=" + value;
            }
            
            history.pushState(null, null, url);
        }

        // 监听窗口大小变化
        window.onresize = function() {
            table.resize('productTable');
        };
    });
</script>
>
</html>